/**@author: Administrator
 * @date: 2013-4-2
 * @Description:
 */
package org.benxiong.iplay.ui.adapter;

import java.util.ArrayList;
import java.util.List;

import org.benxiong.iplay.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author Administrator
 *
 */
public class ConversationAdapter extends BaseAdapter{
	private List data = new ArrayList();
	
	private LayoutInflater inflater;
	
	public ConversationAdapter(Context context) {
		inflater = LayoutInflater.from(context);
	}
	
	public void addItem(String word) {
		data.add(word);
		notifyDataSetChanged();
	}
	
	public void setData(List data) {
		this.data = data;
		notifyDataSetChanged();
	}
	
	public void addData(List data) {
		this.data.addAll(data);
		notifyDataSetChanged();
	}
	
	public void addDataToFront(List data) {
		this.data.add(0, data);
		notifyDataSetChanged();
	}
	/* (non-Javadoc)
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = inflater.inflate(R.layout.conversation_list_item, null);
		TextView tv = (TextView) convertView.findViewById(R.id.msg);
		tv.setText(""+data.get(position));
		return convertView;
	}

}
